package modelLag;
import java.util.ArrayList;

/**
 * Write a description of class Loan here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVD
{
    // instance variables - replace the example below with your own
    private int barcode;
    private String title, artist, publicationDate;
    private ArrayList<Copy> copiesList;

    /**
     * Constructor for objects of class Loan
     */
    public DVD(int barcode, String title, String artist, String publicationDate)
    {
        this.barcode = barcode;
        this.title = title;
        this.artist = artist;
        this.publicationDate = publicationDate;
        copiesList = new ArrayList<Copy>();
    }

    //set & get for barcode 
    public int getBarcode() {
        return barcode;
    }

    public void setBarcode(int barcode) {
        this.barcode = barcode;
    }

    //set & get for title
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    //set & get for Artist
    public String getArtist() {
        return artist;
    }

    public void setArtist(String artist) {
        this.artist = artist;
    }

    //set & get for publication date
    public String getPublicationDate() {
        return publicationDate;
    }

    public void setPublicationDate(String publicationDate) {
        this.publicationDate = publicationDate;
    }

    public void printDVDInfo() {
        System.out.println("-------------------------------------------------"+"\n");
        System.out.println(" Title              :   "+ title+"\n");
        System.out.println(" Artist             :   "+artist+"\n");
        System.out.println(" Publication Date   :   "+publicationDate+"\n");
        System.out.println(" Barcode            :   "+barcode+"\n");
        System.out.println("-------------------------------------------------"+"\n");
    }

    public void addCopy(Copy c){
        copiesList.add(c);
    }

    public void deleteCopy(int serialNumber) {
        int i=0;
        boolean found = false;
        while(i<copiesList.size() && !found) {
            Copy copy = copiesList.get(i);
            int serial  = copy.getSerial();
            if (serial == serialNumber) {
                found = true;
            }
            else {
                i++; 
            }
        }
        if (found) {
            copiesList.remove(i);
        }
    }

    public Copy findCopy(int serialNumber) {
        int i=0;
        boolean found = false;
        Copy cop = null;
        while(i<copiesList.size() && !found){
            Copy copy = copiesList.get(i);
            int serial  = copy.getSerial();
            if (serial == serialNumber) {
                found = true;
                cop = copy;
            }
            else {
                i++; 
            }
        }
        return cop;
    }
}











